import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from '@/router/routes'
// const routes = () => import('@/router/routes')

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  routes
})

// 挂载全局前置守卫
router.beforeEach((to, from, next) => {
  // 如果去访问登录 都方形
  if (to.path === '/login') return next()
  // 获取token 有就可以跳 没有就去登录页
  const token = sessionStorage.getItem('token')
  if (!token) return next('/login')
  next()
})
export default router
